import 'package:flutter/material.dart';

class Test004 extends StatefulWidget {
  const Test004({super.key});

  @override
  State<Test004> createState() => _Test004State();
}

class _Test004State extends State<Test004> {
  var end = 0.0;

  void sop1(String p1, {String p2 = "", String p3 = ""}) {}

  void sop2(String p1, [String p2 = "", String p3 = ""]) {}

  void sop() {
    sop1("", p3: "");
    sop2("", "", "");
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("动画"),
      ),
      body: Center(
        child: Container(
          height: 140,
          width: 300,
          color: Colors.blue,
          child: TweenAnimationBuilder<double>(
            duration: const Duration(milliseconds: 200),
            tween: Tween(end: end),
            builder: (BuildContext context, double value, Widget? child) {
              var whole = value ~/ 1;
              var decimal = value - whole;
              return Stack(
                children: [
                  Positioned(
                    top: -100 * decimal,
                    child: Opacity(
                      opacity: 1.0 - decimal,
                      child: Text(
                        "$whole",
                        style: const TextStyle(fontSize: 100),
                      ),
                    ),
                  ),
                  Positioned(
                    top: 100 - decimal * 100,
                    child: Opacity(
                      opacity: decimal,
                      child: Text(
                        "${whole + 1}",
                        style: const TextStyle(fontSize: 100),
                      ),
                    ),
                  )
                ],
              );
            },
          ),
        ),
      ),
      floatingActionButton: Row(
        children: [
          OutlinedButton(
            onPressed: () {
              setState(() {
                end++;
              });
            },
            child: const Icon(Icons.add),
          ),
          OutlinedButton(
            onPressed: () {
              setState(() {
                end--;
                if (end < 0) {
                  end = 0;
                }
              });
            },
            child: const Icon(Icons.download),
          ),
        ],
      ),
    );
  }
}
